package com.jcl.recruit.core.config;

import com.jcl.core.web.filter.CostTimeFilter;
import com.jcl.core.web.filter.RequestSecurityFilter;
import com.jcl.core.web.filter.XSSFilter;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @ClassName FilterConfig

 * @Author yyliu
 * @Date 2018/9/5 16:58
 * @Version 1.0
 **/
@Configuration
//@ServletComponentScan
public class WebSecurityConfig {


    /* *
     * @Author yyliu
     * @Description xss 安全过滤
     * @Date 16:15 2018/9/19
     **/
    @Bean
    public FilterRegistrationBean xssFilterRegistration() {
        FilterRegistrationBean registrationBean = new FilterRegistrationBean();
        registrationBean.setName("xssFilter");
        XSSFilter filter = new XSSFilter();
        registrationBean.setFilter(filter);
        registrationBean.addUrlPatterns("/*");
        registrationBean.addInitParameter("paramName", "paramValue");
        registrationBean.setOrder(FilterRegistrationBean.LOWEST_PRECEDENCE - 2);
        return registrationBean;
    }

    /* *
     * @Author yyliu
     * @Description 安全验证
     * @Date 16:15 2018/9/19
     **/
    @Bean
    public FilterRegistrationBean requestSecurityFilterRegistration() {
        FilterRegistrationBean registrationBean = new FilterRegistrationBean();
        registrationBean.setName("requestSecurityFilter");
        RequestSecurityFilter filter = new RequestSecurityFilter();
        registrationBean.setFilter(filter);
        registrationBean.addUrlPatterns("/*");
        registrationBean.addInitParameter("paramName", "paramValue");
        registrationBean.setOrder(FilterRegistrationBean.LOWEST_PRECEDENCE - 1);
        return registrationBean;
    }

    /* *
     * @Author yyliu
     * @Description 请求时间打印
     * @Date 16:15 2018/9/19
     **/
    @Bean
    public FilterRegistrationBean costTimeFilterRegistration() {
        FilterRegistrationBean registrationBean = new FilterRegistrationBean();
        registrationBean.setName("costTimeFilter");
        CostTimeFilter filter = new CostTimeFilter();
        registrationBean.setFilter(filter);
        registrationBean.addUrlPatterns("/*");
        registrationBean.addInitParameter("paramName", "paramValue");
        registrationBean.setOrder(FilterRegistrationBean.LOWEST_PRECEDENCE);
        return registrationBean;
    }
}
